Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 905)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.01877 13.01515 13.01157 13.00803 13.00452 13.00106 12.99763 12.99423
## [9] 12.99088 12.98756 12.98429 12.98105 12.97785 12.97469 12.97158 12.96850
## [17] 12.96546 12.96246 12.95951 12.95659 12.95372 12.95089 12.94810 12.94536
## [25] 12.94266 12.94000 12.93738 12.93481 12.93228 12.92979 12.92735 12.92496
## [33] 12.92261 12.92030 12.91804 12.91583 12.91366 12.91154 12.90946 12.90743
## [41] 12.90545 12.90352 12.90163 12.89980 12.89801 12.89627 12.89457 12.89293
## [49] 12.89134 12.88980 12.88832 12.88692 12.88561 12.88437 12.88322 12.88213
## [57] 12.88112 12.88018 12.87932 12.87852 12.87779 12.87712 12.87652 12.87597
## [65] 12.87549 12.87507 12.87470 12.87439 12.87413 12.87393 12.87377 12.87366
## [73] 12.87360 12.87359 12.87361 12.87368 12.87379 12.87393 12.87412 12.87433
## [81] 12.87458 12.87487 12.87518 12.87552 12.87588 12.87627 12.87669 12.87712
## [89] 12.87758 12.87805 12.87854 12.87904 12.87955 12.88008 12.88062 12.88116
## [97] 12.88171 12.88226 12.88282 12.88345 12.88421 12.88510 12.88611 12.88725
## [105] 12.88849 12.88985 12.89131 12.89286 12.89450 12.89623 12.89805 12.89993
## [113] 12.90189 12.90391 12.90598 12.90811 12.91029 12.91251 12.91477 12.91706
## [121] 12.91938 12.92171 12.92406 12.92642 12.92879 12.93115 12.93351 12.93585
## [129] 12.93818 12.94048 12.94276 12.94500 12.94720 12.94935 12.95146 12.95351
## [137] 12.95550 12.95742 12.95927 12.96104 12.96360 12.96772 12.97324 12.98003
## [145] 12.98792 12.99678 13.00644 13.01677 13.02762 13.03883 13.05025 13.06174
## [153] 13.07315 13.08433 13.09513 13.10540 13.11499 13.12375 13.13154 13.13820
## [161] 13.14358 13.14755 13.14994 13.15166 13.15371 13.15606 13.15867 13.16152
## [169] 13.16458 13.16783 13.17123 13.17476 13.17838 13.18208 13.18582 13.18957
## [177] 13.19331 13.19700 13.20063 13.20416 13.20756 13.21081 13.21387 13.21673
## [185] 13.21934 13.22169 13.22374 13.22547 13.22685 13.22785 13.22844 13.22860
## [193] 13.22829 13.22749 13.22617 13.22430 13.22186 13.21881 13.21513 13.21078
## [201] 13.20575 13.20000 13.19351 13.18625 13.17760 13.16708 13.15487 13.14110
## [209] 13.12596 13.10959 13.09216 13.07383 13.05476 13.03511 13.01505 12.99472
## [217] 12.97429 12.95393 12.93379 12.91403 12.89482 12.87632 12.85868 12.84206
## [225] 12.82664 12.81256 12.79835 12.78252 12.76519 12.74649 12.72655 12.70551
## [233] 12.68348 12.66059 12.63699 12.61279 12.58813 12.56313 12.53792 12.51263
## [241] 12.48740 12.46234 12.43760 12.41329 12.38955 12.36650 12.34428 12.32301
## [249] 12.30283 12.28386 12.26623 12.25007 12.23478 12.21968 12.20475 12.19000
## [257] 12.17541 12.16099 12.14673 12.13262 12.11865 12.10482 12.09113 12.07757
## [265] 12.06413 12.05082 12.03761 12.02452 12.01153 11.99863 11.98583 11.97311
## [273] 11.96047 11.94791 11.93542 11.92334 11.91197 11.90129 11.89123 11.88177
## [281] 11.87285 11.86445 11.85651 11.84898 11.84184 11.83504 11.82852 11.82227
## [289] 11.81622 11.81033 11.80457 11.79890 11.79326 11.78762 11.78193 11.77616
## [297] 11.77025 11.76418 11.75788 11.75133 11.74448 11.73729 11.72971 11.72138
## [305] 11.71206 11.70183 11.69081 11.67910 11.66681 11.65404 11.64089 11.62747
## [313] 11.61389 11.60025 11.58666 11.57322 11.56003 11.54721 11.53484 11.52306
## [321] 11.51194 11.50161 11.49216 11.48370 11.47634 11.47018 11.46532 11.46188
## [329] 11.45995 11.45830 11.45572 11.45232 11.44823 11.44358 11.43849 11.43309
## [337] 11.42750 11.42184 11.41624 11.41083 11.40573 11.40107 11.39696 11.39354
## [345] 11.39093 11.38926 11.38864 11.38921 11.39109 11.39440 11.39927 11.40582
## [353] 11.41440 11.42515 11.43793 11.45260 11.46901 11.48702 11.50649 11.52726
## [361] 11.54920 11.57217 11.59601 11.62058 11.64574 11.67135 11.69725 11.72331
## [369] 11.74938 11.77532 11.80099 11.82623 11.85090 11.87486 11.89797 11.92008
## [377] 11.94105 11.96073 11.97898 11.99565 12.01290 12.03281 12.05515 12.07968
## [385] 12.10618 12.13439 12.16409 12.19503 12.22699 12.25973 12.29301 12.32659
## [393] 12.36025 12.39373 12.42681 12.45926 12.49083 12.52128 12.55039 12.57792
## [401] 12.60363 12.62728 12.64864 12.66747 12.68354 12.69661 12.70787 12.71867
## [409] 12.72901 12.73890 12.74834 12.75734 12.76591 12.77405 12.78177 12.78908
## [417] 12.79597 12.80246 12.80856 12.81426 12.81957 12.82451 12.82906 12.83326
## [425] 12.83708 12.84056 12.84368 12.84645 12.84889 12.85010 12.84930 12.84662
## [433] 12.84222 12.83623 12.82880 12.82008 12.81021 12.79934 12.78760 12.77516
## [441] 12.76214 12.74870 12.73497 12.72111 12.70727 12.69357 12.68017 12.66722
## [449] 12.65485 12.64322 12.63247 12.62274 12.61417 12.60692 12.60112 12.59485
## [457] 12.58623 12.57550 12.56287 12.54858 12.53286 12.51594 12.49804 12.47939
## [465] 12.46023 12.44078 12.42127 12.40194 12.38300 12.36468 12.34723 12.33086
## [473] 12.31580 12.30229 12.29055 12.28081 12.27330 12.26825 12.26467 12.26139
## [481] 12.25840 12.25571 12.25331 12.25118 12.24932 12.24772 12.24638 12.24529
## [489] 12.24444 12.24382 12.24343 12.24325 12.24329 12.24353 12.24397 12.24460
## [497] 12.24541 12.24640 12.24756 12.24887 12.25034 12.25196 12.25371 12.25559
## [505] 12.25760 12.25973 12.26298 12.26828 12.27549 12.28448 12.29510 12.30722
## [513] 12.32070 12.33540 12.35118 12.36791 12.38545 12.40366 12.42239 12.44153
## [521] 12.46092 12.48042 12.49991 12.51924 12.53827 12.55687 12.57490 12.59221
## [529] 12.60868 12.62417 12.63853 12.65163 12.66333 12.67349 12.68198 12.68866
## [537] 12.69338 12.69601 12.69642 12.69526 12.69329 12.69057 12.68713 12.68301
## [545] 12.67825 12.67290 12.66698 12.66054 12.65362 12.64627 12.63851 12.63039
## [553] 12.62195 12.61323 12.60427 12.59510 12.58578 12.57633 12.56680 12.55723
## [561] 12.54765 12.53811 12.52865 12.51931 12.51012 12.50113 12.49237 12.48389
## [569] 12.47572 12.46664 12.45551 12.44248 12.42774 12.41143 12.39374 12.37482
## [577] 12.35484 12.33398 12.31239 12.29025 12.26772 12.24496 12.22215 12.19945
## [585] 12.17703 12.15506 12.13369 12.11310 12.09346 12.07493 12.05768 12.04187
## [593] 12.02768 12.01526 12.00479 11.99463 11.98310 11.97034 11.95646 11.94159
## [601] 11.92585 11.90936 11.89225 11.87464 11.85666 11.83842 11.82005 11.80168
## [609] 11.78342 11.76540 11.74774 11.73057 11.71401 11.69818 11.68320 11.66921
## [617] 11.65631 11.64465 11.63432 11.62547 11.61822 11.61268 11.60898 11.60706
## [625] 11.60668 11.60774 11.61013 11.61376 11.61850 11.62426 11.63092 11.63839
## [633] 11.64655 11.65529 11.66452 11.67412 11.68398 11.69401 11.70409 11.71411
## [641] 11.72398 11.73357 11.74280 11.75154 11.75970 11.76716 11.77539 11.78581
## [649] 11.79824 11.81252 11.82849 11.84598 11.86482 11.88485 11.90590 11.92780
## [657] 11.95039 11.97350 11.99697 12.02062 12.04429 12.06782 12.09104 12.11377
## [665] 12.13587 12.15715 12.17746 12.19662 12.21447 12.23085 12.24558 12.25850
## [673] 12.27069 12.28331 12.29631 12.30965 12.32329 12.33719 12.35131 12.36560
## [681] 12.38003 12.39455 12.40912 12.42371 12.43826 12.45274 12.46710 12.48131
## [689] 12.49533 12.50910 12.52259 12.53576 12.54857 12.56098 12.57293 12.58440
## [697] 12.59534 12.60571 12.61547 12.62457 12.63298 12.64080 12.64816 12.65510
## [705] 12.66163 12.66780 12.67361 12.67909 12.68428 12.68919 12.69384 12.69828
## [713] 12.70251 12.70657 12.71048 12.71426 12.71794 12.72155 12.72511 12.72864
## [721] 12.73218 12.73574 12.73934 12.74303 12.74681 12.75072 12.75478 12.75902
## [729] 12.76325 12.76727 12.77110 12.77474 12.77819 12.78147 12.78457 12.78751
## [737] 12.79030 12.79293 12.79541 12.79776 12.79998 12.80207 12.80404 12.80589
## [745] 12.80764 12.80929 12.81085 12.81232 12.81371 12.81502 12.81627 12.81730
## [753] 12.81796 12.81828 12.81829 12.81800 12.81744 12.81663 12.81560 12.81436
## [761] 12.81295 12.81138 12.80968 12.80786 12.80596 12.80400 12.80200 12.79998
## [769] 12.79796 12.79598 12.79404 12.79218 12.79042 12.78878 12.78728 12.78595
## [777] 12.78481 12.78357 12.78198 12.78004 12.77779 12.77525 12.77245 12.76942
## [785] 12.76618 12.76276 12.75919 12.75549 12.75169 12.74783 12.74391 12.73998
## [793] 12.73605 12.73216 12.72833 12.72459 12.72096 12.71747 12.71416 12.71104
## [801] 12.70814 12.70549 12.70311 12.70104 12.69930 12.69791 12.69660 12.69508
## [809] 12.69339 12.69155 12.68958 12.68753 12.68542 12.68326 12.68111 12.67897
## [817] 12.67689 12.67488 12.67298 12.67122 12.66961 12.66820 12.66701 12.66607
## [825] 12.66541 12.66505 12.66502 12.66536 12.66589 12.66643 12.66698 12.66755
## [833] 12.66816 12.66879 12.66946 12.67018 12.67095 12.67177 12.67265 12.67361
## [841] 12.67463 12.67574 12.67693 12.67821 12.67958 12.68106 12.68265 12.68435
## [849] 12.68618 12.68812 12.69020 12.69242 12.69478 12.69729 12.69990 12.70258
## [857] 12.70531 12.70812 12.71099 12.71393 12.71694 12.72002 12.72319 12.72643
## [865] 12.72975 12.73316 12.73666 12.74024 12.74391 12.74768 12.75154 12.75550
## [873] 12.75956 12.76373 12.76800 12.77237 12.77686 12.78146 12.78617 12.79100
## [881] 12.79595 12.80102 12.80623 12.81157 12.81704 12.82266 12.82840 12.83426
## [889] 12.84026 12.84637 12.85260 12.85895 12.86541 12.87197 12.87865 12.88543
## [897] 12.89231 12.89928 12.90635 12.91352 12.92077 12.92811 12.93553 12.94303
## [905] 12.95061
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 905)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.55369 12.55186 12.55007 12.54833 12.54664 12.54500 12.54341 12.54187
## [9] 12.54038 12.53895 12.53756 12.53623 12.53495 12.53373 12.53256 12.53144
## [17] 12.53038 12.52937 12.52842 12.52753 12.52670 12.52592 12.52520 12.52454
## [25] 12.52393 12.52339 12.52291 12.52248 12.52212 12.52182 12.52158 12.52141
## [33] 12.52130 12.52125 12.52126 12.52134 12.52149 12.52170 12.52198 12.52232
## [41] 12.52273 12.52321 12.52375 12.52437 12.52505 12.52580 12.52662 12.52752
## [49] 12.52848 12.52952 12.53065 12.53189 12.53325 12.53471 12.53628 12.53795
## [57] 12.53973 12.54160 12.54357 12.54563 12.54778 12.55001 12.55234 12.55474
## [65] 12.55722 12.55978 12.56242 12.56512 12.56789 12.57073 12.57364 12.57660
## [73] 12.57962 12.58270 12.58583 12.58901 12.59223 12.59550 12.59882 12.60217
## [81] 12.60556 12.60898 12.61243 12.61591 12.61942 12.62295 12.62650 12.63007
## [89] 12.63365 12.63725 12.64085 12.64447 12.64808 12.65170 12.65532 12.65894
## [97] 12.66254 12.66614 12.66973 12.67348 12.67756 12.68195 12.68663 12.69159
## [105] 12.69681 12.70226 12.70793 12.71381 12.71987 12.72609 12.73247 12.73897
## [113] 12.74559 12.75230 12.75908 12.76592 12.77281 12.77971 12.78662 12.79351
## [121] 12.80037 12.80718 12.81392 12.82057 12.82712 12.83354 12.83982 12.84595
## [129] 12.85189 12.85764 12.86318 12.86849 12.87354 12.87833 12.88283 12.88768
## [137] 12.89345 12.90006 12.90743 12.91547 12.92411 12.93325 12.94281 12.95271
## [145] 12.96286 12.97318 12.98358 12.99399 13.00431 13.01446 13.02436 13.03393
## [153] 13.04307 13.05171 13.05976 13.06714 13.07376 13.07954 13.08439 13.08824
## [161] 13.09099 13.09340 13.09627 13.09955 13.10321 13.10721 13.11150 13.11606
## [169] 13.12083 13.12579 13.13089 13.13610 13.14137 13.14667 13.15195 13.15719
## [177] 13.16234 13.16736 13.17222 13.17686 13.18127 13.18539 13.18919 13.19264
## [185] 13.19568 13.19828 13.20041 13.20203 13.20309 13.20356 13.20339 13.20256
## [193] 13.20102 13.19873 13.19565 13.19175 13.18699 13.18132 13.17404 13.16457
## [201] 13.15308 13.13973 13.12467 13.10807 13.09010 13.07091 13.05066 13.02953
## [209] 13.00767 12.98524 12.96241 12.93934 12.91619 12.89311 12.87029 12.84787
## [217] 12.82602 12.80490 12.78468 12.76551 12.74756 12.73098 12.71595 12.70263
## [225] 12.68942 12.67473 12.65869 12.64146 12.62316 12.60395 12.58396 12.56334
## [233] 12.54223 12.52077 12.49910 12.47737 12.45571 12.43427 12.41319 12.39261
## [241] 12.37267 12.35352 12.33529 12.31814 12.30219 12.28760 12.27450 12.26253
## [249] 12.25120 12.24046 12.23028 12.22060 12.21139 12.20259 12.19417 12.18609
## [257] 12.17830 12.17075 12.16340 12.15622 12.14915 12.14215 12.13518 12.12819
## [265] 12.12115 12.11400 12.10671 12.09923 12.09151 12.08352 12.07521 12.06654
## [273] 12.05746 12.04867 12.04085 12.03394 12.02786 12.02255 12.01795 12.01398
## [281] 12.01058 12.00767 12.00520 12.00309 12.00128 11.99970 11.99828 11.99696
## [289] 11.99566 11.99432 11.99288 11.99125 11.98939 11.98721 11.98466 11.98166
## [297] 11.97815 11.97406 11.96931 11.96386 11.95762 11.95024 11.94152 11.93159
## [305] 11.92060 11.90867 11.89596 11.88260 11.86874 11.85450 11.84004 11.82549
## [313] 11.81099 11.79668 11.78270 11.76919 11.75630 11.74415 11.73290 11.72267
## [321] 11.71362 11.70587 11.69958 11.69487 11.69025 11.68423 11.67695 11.66855
## [329] 11.65917 11.64896 11.63805 11.62661 11.61476 11.60265 11.59042 11.57822
## [337] 11.56620 11.55448 11.54322 11.53257 11.52265 11.51362 11.50563 11.49880
## [345] 11.49329 11.48924 11.48680 11.48610 11.48729 11.49052 11.49571 11.50266
## [353] 11.51124 11.52135 11.53289 11.54574 11.55980 11.57496 11.59111 11.60815
## [361] 11.62596 11.64443 11.66347 11.68296 11.70280 11.72287 11.74307 11.76329
## [369] 11.78343 11.80336 11.82300 11.84223 11.86094 11.87902 11.89636 11.91287
## [377] 11.92843 11.94292 11.95820 11.97602 11.99620 12.01852 12.04278 12.06878
## [385] 12.09632 12.12520 12.15522 12.18616 12.21784 12.25005 12.28258 12.31523
## [393] 12.34781 12.38010 12.41192 12.44305 12.47329 12.50244 12.53030 12.55666
## [401] 12.58133 12.60411 12.62478 12.64315 12.65901 12.67217 12.68404 12.69614
## [409] 12.70840 12.72075 12.73314 12.74551 12.75778 12.76990 12.78180 12.79342
## [417] 12.80469 12.81556 12.82595 12.83582 12.84508 12.85368 12.86156 12.86866
## [425] 12.87490 12.88023 12.88458 12.88789 12.89010 12.89053 12.88867 12.88468
## [433] 12.87874 12.87102 12.86167 12.85088 12.83881 12.82563 12.81151 12.79662
## [441] 12.78112 12.76520 12.74901 12.73272 12.71651 12.70054 12.68499 12.67002
## [449] 12.65580 12.64250 12.63029 12.61933 12.60981 12.60188 12.59572 12.58912
## [457] 12.57993 12.56840 12.55480 12.53937 12.52238 12.50408 12.48472 12.46456
## [465] 12.44386 12.42287 12.40186 12.38106 12.36075 12.34118 12.32259 12.30526
## [473] 12.28943 12.27536 12.26330 12.25352 12.24626 12.24179 12.23886 12.23605
## [481] 12.23338 12.23085 12.22848 12.22628 12.22426 12.22242 12.22077 12.21933
## [489] 12.21811 12.21711 12.21635 12.21584 12.21558 12.21558 12.21587 12.21643
## [497] 12.21730 12.21846 12.21995 12.22175 12.22390 12.22638 12.22923 12.23244
## [505] 12.23602 12.23999 12.24548 12.25352 12.26395 12.27660 12.29129 12.30787
## [513] 12.32617 12.34601 12.36724 12.38968 12.41317 12.43754 12.46262 12.48826
## [521] 12.51427 12.54050 12.56677 12.59292 12.61879 12.64420 12.66899 12.69299
## [529] 12.71604 12.73796 12.75860 12.77777 12.79533 12.81110 12.82491 12.83659
## [537] 12.84598 12.85292 12.85723 12.86011 12.86284 12.86541 12.86780 12.87000
## [545] 12.87199 12.87375 12.87528 12.87656 12.87756 12.87828 12.87870 12.87880
## [553] 12.87857 12.87800 12.87706 12.87574 12.87403 12.87191 12.86937 12.86639
## [561] 12.86295 12.85904 12.85465 12.84975 12.84434 12.83840 12.83191 12.82485
## [569] 12.81722 12.80774 12.79531 12.78016 12.76253 12.74263 12.72071 12.69700
## [577] 12.67171 12.64509 12.61736 12.58875 12.55949 12.52982 12.49996 12.47015
## [585] 12.44061 12.41157 12.38326 12.35592 12.32977 12.30505 12.28198 12.26079
## [593] 12.24172 12.22500 12.21084 12.19705 12.18137 12.16395 12.14496 12.12458
## [601] 12.10296 12.08028 12.05668 12.03235 12.00745 11.98214 11.95658 11.93095
## [609] 11.90540 11.88010 11.85523 11.83093 11.80739 11.78476 11.76320 11.74290
## [617] 11.72400 11.70667 11.69109 11.67741 11.66580 11.65642 11.64945 11.64432
## [625] 11.64030 11.63736 11.63542 11.63442 11.63431 11.63502 11.63650 11.63868
## [633] 11.64151 11.64492 11.64886 11.65326 11.65807 11.66323 11.66867 11.67434
## [641] 11.68017 11.68611 11.69210 11.69807 11.70397 11.70973 11.71675 11.72633
## [649] 11.73828 11.75240 11.76853 11.78646 11.80601 11.82700 11.84924 11.87254
## [657] 11.89671 11.92157 11.94693 11.97260 11.99840 12.02414 12.04964 12.07469
## [665] 12.09913 12.12276 12.14540 12.16685 12.18694 12.20547 12.22226 12.23711
## [673] 12.25140 12.26656 12.28251 12.29919 12.31653 12.33446 12.35291 12.37181
## [681] 12.39109 12.41068 12.43051 12.45052 12.47063 12.49077 12.51087 12.53087
## [689] 12.55069 12.57027 12.58953 12.60841 12.62683 12.64474 12.66205 12.67869
## [697] 12.69461 12.70973 12.72397 12.73727 12.74957 12.76124 12.77271 12.78399
## [705] 12.79508 12.80597 12.81666 12.82717 12.83748 12.84761 12.85754 12.86728
## [713] 12.87683 12.88620 12.89537 12.90436 12.91317 12.92178 12.93021 12.93846
## [721] 12.94652 12.95439 12.96209 12.96960 12.97693 12.98408 12.99105 12.99783
## [729] 13.00449 13.01108 13.01756 13.02395 13.03021 13.03635 13.04234 13.04818
## [737] 13.05385 13.05934 13.06464 13.06973 13.07461 13.07926 13.08367 13.08782
## [745] 13.09171 13.09532 13.09864 13.10165 13.10435 13.10672 13.10875 13.11031
## [753] 13.11129 13.11174 13.11168 13.11116 13.11021 13.10886 13.10716 13.10513
## [761] 13.10281 13.10025 13.09746 13.09450 13.09139 13.08817 13.08488 13.08155
## [769] 13.07822 13.07492 13.07169 13.06857 13.06558 13.06278 13.06018 13.05784
## [777] 13.05578 13.05347 13.05039 13.04660 13.04215 13.03710 13.03150 13.02541
## [785] 13.01887 13.01195 13.00469 12.99716 12.98940 12.98147 12.97342 12.96532
## [793] 12.95720 12.94913 12.94117 12.93336 12.92575 12.91841 12.91139 12.90474
## [801] 12.89852 12.89277 12.88756 12.88294 12.87896 12.87568 12.87259 12.86918
## [809] 12.86549 12.86156 12.85745 12.85320 12.84885 12.84444 12.84003 12.83565
## [817] 12.83135 12.82718 12.82317 12.81938 12.81585 12.81263 12.80975 12.80727
## [825] 12.80522 12.80366 12.80263 12.80216 12.80200 12.80185 12.80172 12.80161
## [833] 12.80155 12.80153 12.80158 12.80170 12.80191 12.80220 12.80261 12.80312
## [841] 12.80377 12.80455 12.80548 12.80657 12.80782 12.80926 12.81089 12.81272
## [849] 12.81476 12.81703 12.81953 12.82227 12.82527 12.82853 12.83199 12.83557
## [857] 12.83927 12.84309 12.84703 12.85111 12.85531 12.85965 12.86412 12.86874
## [865] 12.87349 12.87840 12.88344 12.88864 12.89399 12.89950 12.90517 12.91100
## [873] 12.91699 12.92315 12.92947 12.93597 12.94265 12.94950 12.95654 12.96375
## [881] 12.97116 12.97875 12.98654 12.99455 13.00276 13.01117 13.01979 13.02860
## [889] 13.03760 13.04680 13.05617 13.06573 13.07547 13.08538 13.09546 13.10571
## [897] 13.11612 13.12669 13.13742 13.14829 13.15932 13.17049 13.18181 13.19326
## [905] 13.20485
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 905)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.00072 11.99575 11.99087 11.98606 11.98133 11.97667 11.97210 11.96760
## [9] 11.96318 11.95885 11.95459 11.95041 11.94631 11.94229 11.93835 11.93449
## [17] 11.93072 11.92702 11.92340 11.91987 11.91641 11.91304 11.90975 11.90654
## [25] 11.90341 11.90037 11.89741 11.89453 11.89173 11.88902 11.88639 11.88384
## [33] 11.88138 11.87900 11.87670 11.87449 11.87236 11.87032 11.86837 11.86649
## [41] 11.86471 11.86301 11.86139 11.85986 11.85841 11.85706 11.85579 11.85460
## [49] 11.85350 11.85249 11.85157 11.85073 11.84998 11.84932 11.84875 11.84826
## [57] 11.84786 11.84758 11.84744 11.84744 11.84757 11.84784 11.84824 11.84876
## [65] 11.84941 11.85017 11.85106 11.85206 11.85318 11.85440 11.85574 11.85717
## [73] 11.85871 11.86035 11.86208 11.86390 11.86582 11.86782 11.86991 11.87208
## [81] 11.87432 11.87665 11.87904 11.88151 11.88404 11.88664 11.88930 11.89202
## [89] 11.89479 11.89762 11.90050 11.90343 11.90640 11.90941 11.91246 11.91555
## [97] 11.91867 11.92182 11.92500 11.92820 11.93143 11.93467 11.93793 11.94121
## [105] 11.94449 11.94779 11.95122 11.95490 11.95884 11.96301 11.96741 11.97203
## [113] 11.97685 11.98187 11.98707 11.99245 11.99800 12.00370 12.00954 12.01552
## [121] 12.02162 12.02783 12.03415 12.04056 12.04705 12.05362 12.06024 12.06692
## [129] 12.07363 12.08038 12.08715 12.09392 12.10070 12.10746 12.11420 12.12091
## [137] 12.12758 12.13420 12.14075 12.14723 12.15500 12.16530 12.17788 12.19250
## [145] 12.20894 12.22695 12.24630 12.26676 12.28809 12.31005 12.33240 12.35492
## [153] 12.37737 12.39950 12.42109 12.44190 12.46169 12.48023 12.49728 12.51260
## [161] 12.52597 12.53714 12.54588 12.55344 12.56123 12.56922 12.57737 12.58566
## [169] 12.59406 12.60254 12.61108 12.61964 12.62820 12.63673 12.64520 12.65358
## [177] 12.66185 12.66997 12.67792 12.68566 12.69318 12.70044 12.70741 12.71407
## [185] 12.72039 12.72633 12.73188 12.73700 12.74166 12.74584 12.74950 12.75262
## [193] 12.75518 12.75714 12.75847 12.75914 12.75914 12.75842 12.75696 12.75474
## [201] 12.75172 12.74787 12.74318 12.73760 12.73011 12.71988 12.70713 12.69213
## [209] 12.67510 12.65630 12.63597 12.61435 12.59169 12.56824 12.54423 12.51991
## [217] 12.49553 12.47133 12.44755 12.42444 12.40224 12.38120 12.36156 12.34357
## [225] 12.32746 12.31349 12.30001 12.28527 12.26937 12.25242 12.23450 12.21572
## [233] 12.19618 12.17598 12.15521 12.13398 12.11238 12.09051 12.06848 12.04637
## [241] 12.02429 12.00234 11.98061 11.95921 11.93823 11.91778 11.89794 11.87883
## [249] 11.86053 11.84316 11.82680 11.81155 11.79691 11.78227 11.76766 11.75308
## [257] 11.73855 11.72407 11.70966 11.69533 11.68108 11.66693 11.65289 11.63897
## [265] 11.62518 11.61153 11.59804 11.58470 11.57153 11.55855 11.54576 11.53318
## [273] 11.52080 11.50866 11.49675 11.48526 11.47435 11.46399 11.45415 11.44482
## [281] 11.43594 11.42751 11.41950 11.41186 11.40458 11.39763 11.39098 11.38460
## [289] 11.37847 11.37255 11.36682 11.36125 11.35581 11.35047 11.34521 11.34000
## [297] 11.33481 11.32961 11.32438 11.31908 11.31369 11.30818 11.30253 11.29637
## [305] 11.28944 11.28182 11.27359 11.26484 11.25564 11.24609 11.23626 11.22625
## [313] 11.21612 11.20598 11.19589 11.18595 11.17623 11.16682 11.15781 11.14927
## [321] 11.14130 11.13396 11.12736 11.12157 11.11667 11.11274 11.10988 11.10817
## [329] 11.10768 11.10734 11.10611 11.10410 11.10142 11.09820 11.09455 11.09059
## [337] 11.08644 11.08221 11.07803 11.07401 11.07027 11.06693 11.06410 11.06190
## [345] 11.06046 11.05988 11.06028 11.06180 11.06453 11.06860 11.07413 11.08123
## [353] 11.09039 11.10192 11.11565 11.13142 11.14907 11.16844 11.18938 11.21171
## [361] 11.23529 11.25995 11.28553 11.31187 11.33881 11.36620 11.39386 11.42164
## [369] 11.44938 11.47693 11.50411 11.53077 11.55675 11.58189 11.60603 11.62901
## [377] 11.65066 11.67084 11.68937 11.70611 11.72290 11.74160 11.76204 11.78404
## [385] 11.80743 11.83203 11.85768 11.88419 11.91140 11.93913 11.96720 11.99544
## [393] 12.02368 12.05175 12.07946 12.10666 12.13315 12.15878 12.18336 12.20672
## [401] 12.22868 12.24909 12.26775 12.28449 12.29915 12.31155 12.32260 12.33334
## [409] 12.34376 12.35386 12.36363 12.37306 12.38216 12.39092 12.39933 12.40739
## [417] 12.41509 12.42242 12.42940 12.43600 12.44222 12.44807 12.45353 12.45860
## [425] 12.46327 12.46754 12.47141 12.47487 12.47791 12.48009 12.48100 12.48073
## [433] 12.47935 12.47695 12.47361 12.46941 12.46443 12.45875 12.45246 12.44563
## [441] 12.43835 12.43069 12.42274 12.41458 12.40629 12.39795 12.38964 12.38145
## [449] 12.37345 12.36572 12.35836 12.35143 12.34502 12.33921 12.33408 12.32801
## [457] 12.31949 12.30875 12.29602 12.28154 12.26555 12.24829 12.22997 12.21085
## [465] 12.19115 12.17111 12.15096 12.13095 12.11130 12.09225 12.07404 12.05689
## [473] 12.04105 12.02675 12.01422 12.00370 11.99543 11.98964 11.98492 11.97976
## [481] 11.97422 11.96833 11.96217 11.95577 11.94920 11.94250 11.93573 11.92894
## [489] 11.92219 11.91552 11.90900 11.90267 11.89658 11.89080 11.88536 11.88034
## [497] 11.87577 11.87172 11.86823 11.86535 11.86315 11.86167 11.86097 11.86110
## [505] 11.86211 11.86406 11.86749 11.87284 11.87999 11.88881 11.89918 11.91098
## [513] 11.92409 11.93839 11.95375 11.97006 11.98719 12.00502 12.02343 12.04230
## [521] 12.06150 12.08092 12.10043 12.11991 12.13924 12.15830 12.17696 12.19511
## [529] 12.21262 12.22937 12.24524 12.26011 12.27386 12.28636 12.29749 12.30713
## [537] 12.31517 12.32147 12.32591 12.32955 12.33349 12.33768 12.34210 12.34671
## [545] 12.35148 12.35637 12.36135 12.36637 12.37142 12.37644 12.38141 12.38629
## [553] 12.39105 12.39566 12.40007 12.40425 12.40817 12.41179 12.41508 12.41800
## [561] 12.42052 12.42260 12.42422 12.42532 12.42588 12.42587 12.42525 12.42398
## [569] 12.42203 12.41896 12.41442 12.40854 12.40141 12.39315 12.38386 12.37365
## [577] 12.36264 12.35093 12.33862 12.32584 12.31268 12.29926 12.28568 12.27206
## [585] 12.25850 12.24511 12.23201 12.21929 12.20708 12.19547 12.18457 12.17450
## [593] 12.16537 12.15728 12.15034 12.14303 12.13386 12.12297 12.11052 12.09665
## [601] 12.08151 12.06526 12.04803 12.02999 12.01129 11.99206 11.97246 11.95264
## [609] 11.93275 11.91294 11.89336 11.87416 11.85548 11.83748 11.82030 11.80410
## [617] 11.78903 11.77523 11.76285 11.75205 11.74297 11.73576 11.73057 11.72693
## [625] 11.72422 11.72238 11.72136 11.72109 11.72153 11.72261 11.72427 11.72646
## [633] 11.72912 11.73219 11.73562 11.73934 11.74330 11.74745 11.75172 11.75605
## [641] 11.76040 11.76469 11.76888 11.77291 11.77671 11.78023 11.78456 11.79072
## [649] 11.79858 11.80798 11.81880 11.83090 11.84413 11.85835 11.87343 11.88923
## [657] 11.90560 11.92241 11.93952 11.95679 11.97408 11.99124 12.00815 12.02466
## [665] 12.04063 12.05592 12.07039 12.08390 12.09632 12.10751 12.11732 12.12561
## [673] 12.13322 12.14104 12.14907 12.15728 12.16564 12.17414 12.18275 12.19146
## [681] 12.20024 12.20907 12.21793 12.22680 12.23566 12.24448 12.25324 12.26193
## [689] 12.27052 12.27900 12.28733 12.29549 12.30348 12.31126 12.31882 12.32612
## [697] 12.33316 12.33991 12.34635 12.35246 12.35822 12.36364 12.36880 12.37371
## [705] 12.37837 12.38280 12.38702 12.39105 12.39489 12.39856 12.40207 12.40545
## [713] 12.40870 12.41184 12.41488 12.41784 12.42073 12.42357 12.42637 12.42915
## [721] 12.43192 12.43469 12.43748 12.44030 12.44318 12.44611 12.44913 12.45223
## [729] 12.45533 12.45832 12.46119 12.46396 12.46662 12.46918 12.47163 12.47399
## [737] 12.47625 12.47841 12.48048 12.48246 12.48435 12.48616 12.48788 12.48953
## [745] 12.49109 12.49258 12.49399 12.49533 12.49661 12.49781 12.49895 12.50000
## [753] 12.50093 12.50175 12.50246 12.50307 12.50358 12.50400 12.50433 12.50459
## [761] 12.50477 12.50488 12.50492 12.50491 12.50484 12.50473 12.50457 12.50437
## [769] 12.50414 12.50389 12.50361 12.50332 12.50302 12.50271 12.50240 12.50210
## [777] 12.50180 12.50143 12.50091 12.50023 12.49941 12.49847 12.49740 12.49623
## [785] 12.49495 12.49359 12.49214 12.49063 12.48905 12.48742 12.48575 12.48405
## [793] 12.48233 12.48059 12.47886 12.47713 12.47542 12.47373 12.47209 12.47049
## [801] 12.46894 12.46747 12.46607 12.46475 12.46353 12.46242 12.46120 12.45967
## [809] 12.45786 12.45581 12.45355 12.45113 12.44857 12.44590 12.44318 12.44042
## [817] 12.43766 12.43494 12.43230 12.42976 12.42737 12.42515 12.42315 12.42139
## [825] 12.41992 12.41877 12.41797 12.41755 12.41731 12.41703 12.41671 12.41635
## [833] 12.41597 12.41557 12.41517 12.41476 12.41437 12.41399 12.41363 12.41331
## [841] 12.41304 12.41281 12.41264 12.41253 12.41250 12.41255 12.41269 12.41293
## [849] 12.41328 12.41374 12.41432 12.41504 12.41589 12.41690 12.41799 12.41913
## [857] 12.42030 12.42151 12.42276 12.42405 12.42539 12.42678 12.42821 12.42970
## [865] 12.43124 12.43284 12.43449 12.43621 12.43798 12.43982 12.44172 12.44368
## [873] 12.44572 12.44783 12.45001 12.45226 12.45460 12.45701 12.45950 12.46207
## [881] 12.46473 12.46747 12.47031 12.47326 12.47630 12.47945 12.48270 12.48603
## [889] 12.48946 12.49298 12.49658 12.50027 12.50404 12.50788 12.51180 12.51579
## [897] 12.51985 12.52398 12.52817 12.53242 12.53673 12.54110 12.54551 12.54998
## [905] 12.55450
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")